package com.xiaohai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaohai.projo.Major;
import com.xiaohai.mapper.MajorMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaohai.projo.dto.MajorDto;
import com.xiaohai.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xiaohai
 * @since 2024-02-24
 */
@Service
public class MajorServiceImpl extends ServiceImpl<MajorMapper, Major> implements MajorService {

    @Autowired
    private MajorMapper majorMapper;
    @Override
    public boolean mySave(Major major) {
        String name = major.getName();
        LambdaQueryWrapper<Major> majorLambdaQueryWrapper = new LambdaQueryWrapper<>();
        majorLambdaQueryWrapper.eq(name != null, Major::getName, name);

        Major one = super.getOne(majorLambdaQueryWrapper);
        if (Objects.isNull(one)) {
            return super.save(major);

        }
        return false;
    }

    @Override
    public Major detail(String id) {
        return super.getById(id);
    }

    @Override
    public boolean myUpdate(Major major) {
        return super.updateById(major);
    }

    @Override
    public List<MajorDto> majorPerson() {
        return majorMapper.majorPerson();
    }
}
